package com.naiterui.ehp.bs.esign.controller.inner;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.esign.api.scca.util.SignSccaUtil;
import com.naiterui.ehp.bs.esign.api.wukong.helper.OpenApiHelper;
import com.naiterui.ehp.bs.esign.exception.ExceptionCodes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luao
 * @date 2022/4/27 3:32 PM
 **/
@Api(tags = {SwaggerTag.ESIGN + SwaggerTag.INNER_API + SwaggerTag.SELF_INSPECT})
@RestController
@RequestMapping("esign/inner/self/inspect")
@RequiredArgsConstructor
public class EsignInnerSelfInspectController {

    private final OpenApiHelper openApiHelper = new OpenApiHelper();

    @ApiOperation(value = "e签宝自检")
    @GetMapping("/esign")
    public void esign() throws BusinessException {
        String accessToken = openApiHelper.accessToken();
        if (accessToken == null) {
            throw new BusinessException(ExceptionCodes.FAILED, "e签宝自检失败");
        }
    }

    @ApiOperation(value = "四川CA自检")
    @GetMapping("/scca")
    public String scca() throws BusinessException {
        try {
            return SignSccaUtil.generateQRCode("selfInspect", null);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ExceptionCodes.FAILED, "四川CA自检失败");
        }
    }
}
